//
//  XMGiftCollectionViewCell.m
//  XunMi
//
//  Created by MacBook on 2024/4/12.
//  Copyright © 2024 TieZhu. All rights reserved.
//

#import "XMGiftCollectionViewCell.h"
#import "XMGiftModel.h"

@interface XMGiftCollectionViewCell ()
@property (weak, nonatomic) IBOutlet UIButton *bgButton;
@property (weak, nonatomic) IBOutlet UIImageView *imgV;
@property (weak, nonatomic) IBOutlet UILabel *nameLa;
@property (weak, nonatomic) IBOutlet UIButton *priceButton;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomSpace;


@end

@implementation XMGiftCollectionViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    [self.priceButton setImagePosition:XMImagePositionLeft spacing:2];
    [self.bgButton setBackgroundImage:[UIImage imageWithColor:UIColor.whiteColor] forState:UIControlStateNormal];
}

- (IBAction)sendAct:(UIButton *)sender {
    if (self.sendBlock) {
        self.sendBlock(self.model);
    }
}

- (void)setModel:(XMGiftModel *)model {
    _model = model;
    [self.imgV sd_setImageWithURL:kStringToUrl(model.image.file_url) placeholderImage:kDefaultCoverImg];
    self.nameLa.text = model.name;
    [self.priceButton setTitle:kValueToString(model.golds) forState:UIControlStateNormal];
    self.bgButton.selected = model.selected;
    
    if (model.selected) {
        self.nameLa.hidden = YES;
        self.sendButton.hidden = NO;
        self.bottomSpace.constant = 30;
    } else {
        self.nameLa.hidden = NO;
        self.sendButton.hidden = YES;
        self.bottomSpace.constant = 5;
    }
}

@end
